<!--

/*
* Copyright (C) 2005-2013 University of Sydney
*
* Licensed under the GNU License, Version 3.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

/**
* brief description of file
*
* @author      Tom Murtagh
* @author      Kim Jackson
* @author      Ian Johnson   <ian.johnson@sydney.edu.au>
* @author      Stephen White   <stephen.white@sydney.edu.au>
* @author      Artem Osmakov   <artem.osmakov@sydney.edu.au>
* @copyright   (C) 2005-2013 University of Sydney
* @link        http://Sydney.edu.au/Heurist
* @version     3.1.0
* @license     http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
* @package     Heurist academic knowledge management system
* @subpackage  !!!subpackagename for file such as Administration, Search, Edit, Application, Library
*/

-->
<!--

/**
 * manageTags.html
 * @copyright (C) 2005-2010 University of Sydney Digital Innovation Unit.
 * @link: http://HeuristScholar.org
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
 * @package Heurist academic knowledge management system
 * @todo
 **/

-->
<html>
<head>
<title>Manage tags</title>
<link rel="stylesheet" type="text/css" href= "../../common/css/global.css">
<link rel="stylesheet" type="text/css" href= "../../common/css/admin.css">
<style type="text/css">
#tag_scroll_region {
	background-color: #FFFFFF;
	bottom: 50px;
	left: 20px;
	overflow: auto;
	padding: 3px;
	position: absolute;
	right: 20px;
	top: 80px;
}
.actionButtons {
	bottom: 10px;
	left: 20px;
	position: absolute;
	right: 20px;
}
#tag_scroll_region .textinput, #tag_scroll_region select {
	width: 200px;
	background-color: #ECF1FB;
	border: 1px solid #DCDCDC;
	min-width: 40ex;
	padding:3px;
	height:20px
}
#tag_scroll_region .replace input {
	width: 60px;
}
#tag_scroll_region img {
	vertical-align: middle;
	cursor: pointer;
	margin: 1px;
}
.u-cell {
	width: 100%;
}
.u {
	background-color: #EEE;
	width: 100%;
	height: 10px;
}
.u div {
	background-color: #6A7C99;
	height: 10px;
}
.count {
	text-align:right;
	margin:0 5px;
}
.search {}
.search a{}
.success {
	padding: 3px;
	font-weight: bold;
	color: green;
}
.failure {
	padding: 3px;
	font-weight: bold;
	color: red;
}
#ignored_hyperlinks {
	height: 80px;
	overflow: auto;
	background-color: #EEEEEE;
	padding-left: 5px;
}
.externalLink:hover {
    background-color: rgba(100, 100, 100, 0.4);
    box-shadow: 0 1px 3px #000000 inset;
}
.externalLink {
    border-radius: 3px 3px 3px 3px;
    display: inline;
    float: right;
    height: 16px;
    width: 16px;
}
</style>
<script type="text/javascript">
<!--

	function delete_kwd(tag_ID, tag_Text, use_count) {
		if (use_count == 0) {
			if (! confirm('Tag "'+tag_Text+'" is currently unused. Remove forever?')) return;
		} else if (use_count == 1) {
			if (! confirm('Tag "'+tag_Text+'" is used by one bookmark. Do you want to remove the tag?')) return;
		} else {
			if (! confirm('Tag "'+tag_Text+'" is used by '+use_count+' bookmarks. Do you want to remove the tag?')) return;
		}

		document.forms['kwd_edit_form'].elements['delete_kwd_id'].value = tag_ID;
		document.forms['kwd_edit_form'].submit();
	}

	function delete_multiple() {
		document.forms['kwd_edit_form'].elements['delete_multiple_kwds'].value = 1;
		document.forms['kwd_edit_form'].submit();
	}

	function rename_kwd(tag_ID, kwd_obj) {
		if (kwd_obj.value == '') {
			alert('Tag cannot be empty');
			kwd_obj.value = kwd_obj.defaultValue;
			kwd_obj.focus();
			return false;
		}

		if (kwd_obj.value.indexOf(',') >= 0) {
			alert('Tag cannot contain commas');
			kwd_obj.value = kwd_obj.defaultValue;
			kwd_obj.focus();
			return false;
		}

		if (kwd[kwd_obj.value.toLowerCase()]  &&  kwd[kwd_obj.value.toLowerCase()] != tag_ID) {
			if (confirm('You already have a tag called "'+kwd_obj.value+'".\nDo you want to change all "'+kwd_obj.defaultValue+'" references to "'+kwd_obj.value+'" references, and remove "'+kwd_obj.defaultValue+'"?')) {
				document.forms['kwd_edit_form'].elements['update_kwd_from'].value = tag_ID;
				document.forms['kwd_edit_form'].elements['update_kwd_to'].value = kwd[kwd_obj.value.toLowerCase()];
				document.forms['kwd_edit_form'].submit();
			} else {
				kwd_obj.value = kwd_obj.defaultValue;
				kwd_obj.focus();
				return false;
			}
		}

		kwd[kwd_obj.defaultValue.toLowerCase()] = 0;
		kwd[kwd_obj.value.toLowerCase()] = tag_ID;

		document.forms['kwd_edit_form'].elements['change_names'].value = 1;
		return true;
	}

	function show_replace_list(elt, tag_ID) {
		var replace_link = elt;
		var container = replace_link.parentNode;
		var sel = document.getElementById("kwd_select").cloneNode(true);

		container.removeChild(replace_link);

		container.appendChild(document.createTextNode("replace with: "));

		container.appendChild(sel);
		sel.style.display = "";

		container.appendChild(document.createTextNode(" "));

		var b = document.createElement("input");
		b.type = "button";
		b.value = "replace";
		b.onclick = function() {
			if (! sel.value) { alert("Select a tag"); return; }
			document.forms["kwd_edit_form"].elements["replace_kwd"].value = 1;
			document.forms["kwd_edit_form"].elements["replace_kwd_id"].value = tag_ID;
			document.forms["kwd_edit_form"].elements["replace_with_kwd_id"].value = sel.value;
			document.forms["kwd_edit_form"].submit();
		};
		container.appendChild(b);

		container.appendChild(document.createTextNode(" "));

		var b = document.createElement("input");
		b.type = "button";
		b.value = "cancel";
		b.onclick = function() {
			while (container.firstChild) container.removeChild(container.firstChild);
			container.appendChild(replace_link);
		}
		container.appendChild(b);
	}
//-->
</script>
</head>

<body style="padding:20px" class="popup" onLoad="if ('{section}' != ''  &&  (enddoc=document.getElementById('enddoc'))  &&  (elt=document.getElementById('{section}'))) { enddoc.focus(); elt.focus(); elt.blur(); }">


<div class="hide_on_bookmark_import"> <a name="tag_edit">
	</a> {TagMessage}
	<div>
		<script type="text/javascript">

var kwd = new Object();
{ForeachTagJs}

</script>
		<form method="post" action="configureProfile.php" name="kwd_edit_form">
			<input type="hidden" name="db" value="{database}">
			{body_only}
			<input type="hidden" name="tag_edit" value="{tag_edit}">
			{sortby_input}

 {sortby_button}
			to change tag labels: edit labels below and click "Update tags" <br>to delete multiple tags, select with checkboxes and click "Delete selected tags"<br>
 <br clear="all">
  <div id=tags-loading>Loading tag data ...</div>
 <div id="tag_scroll_region">
  <table border="0" style="display: none;" id=tags-table>
    {ForeachTag}
  </table>
 </div>
  <script>
/* get rid of scary flickery effect that occurs when some numbnut with 1000 tags loads this page */
document.getElementById("tags-loading").style.display = "none";
document.getElementById("tags-table").style.display = "block";
  </script>
 <div class="actionButtons">
 <input type="button" value="Update tags" style="font-weight: bold;">
 <input type="button" value="Delete selected tags" style="font-weight: bold;" onClick="delete_multiple();">
 <input type="hidden" name="delete_kwd_id" value="0">
 <input type="hidden" name="update_kwd_from" value="0">
 <input type="hidden" name="update_kwd_to" value="0">
 <input type="hidden" name="change_names" value="0">
 <input type="hidden" name="replace_kwd" value="0">
 <input type="hidden" name="replace_kwd_id" value="0">
 <input type="hidden" name="replace_with_kwd_id" value="0">
 <input type="hidden" name="delete_multiple_kwds" value="0">
			</div>
		</form>
	</div>
</div>
{kwd_select} <a href="#" style="text-decoration: none;" onClick="return false;" id="enddoc">&nbsp;</a>
</body>
</html>
